<?php

namespace Biz;

use Base\BaseOrmModel;
use Base\Exception\NoRecordException;

class SharingLog extends \Base\BaseBiz
{
    /**
     * @param $where
     * @param $now
     * @param $size
     * @return array
     * 获取用户分享记录列表
     */
    public function getSharingLogList($where, $now, $size)
    {
        $sharing_log = \Biz\SharingLog\SharingLog::getList($where, $now, $size);
        $user = new \Orm\User\UserClass();
        $winning_list_cls = array();
        $winning_list_cls['total'] = $sharing_log['total'];
        $winning_list_cls['list'] = array();
        foreach ($sharing_log['lists'] as $key => $value){
            try {
                $user->loadById($value['user_id']);
                $winning_list_cls['list'][$key]['username'] = $user['nickname'];
            }catch (\Exception $e) {
                $winning_list_cls['list'][$key]['username'] = '--';
            }
            $winning_list_cls['list'][$key]['id'] = $value['id'];
            $winning_list_cls['list'][$key]['title'] = $value['title'];
            $winning_list_cls['list'][$key]['desc'] = $value['desc'];
            $winning_list_cls['list'][$key]['link'] = $value['link'];
            $winning_list_cls['list'][$key]['imgUrl'] = $value['imgUrl'];
            $winning_list_cls['list'][$key]['insert_time'] = $value['insert_time'];
            $winning_list_cls['list'][$key]['share_goals'] = $value['share_goals'];
        }
        return $winning_list_cls;
    }


    /**
     * @param $user_id
     * @param $time
     * @return mixed
     * 根据用户id和当前时间（Y-m-d）格式获取用户分享次数
     */
    public static function getShareByUidAndTime($user_id,$time){
       return \Biz\SharingLog\SharingLog::getShareByUidAndTime($user_id,$time);
    }

}